package com.tx.review.annotation.element;

import com.tx.review.annotation.Inherited.DocumentA;
import com.tx.review.annotation.Inherited.DocumentB;

import java.lang.annotation.Annotation;
import java.util.Arrays;

/**
 * @author ：tx
 * @version:
 */
public class AnnotationElementTest {
    public static void main(String[] args) throws NoSuchMethodException {
        Class childClass = Child.class;

        //getAnnotation:可以获得父类的注解
        testGetAnnotation(childClass);


        //getAnnotations：获取所有注解，包括父类
        testGetAnnotations(childClass);

        //getDeclaredAnnotations:获取所有注解，不包括父类
        testGetDeclaredAnnotations(childClass);

        //isAnnotationPresent：判断注解是否在该类上
        testIsAnnotationPresent(childClass);
    }

    private static void testIsAnnotationPresent(Class childClass) {
        boolean b = childClass.isAnnotationPresent(DocumentA.class);
        System.out.println(b);
    }


    private static void testGetDeclaredAnnotations(Class childClass) {
        Annotation[] declaredAnnotations = childClass.getDeclaredAnnotations();
        System.out.println(Arrays.toString(declaredAnnotations));
    }

    private static void testGetAnnotations(Class childClass) {
        Annotation[] annotations = childClass.getAnnotations();
        System.out.println(Arrays.toString(annotations));
    }

    private static void testGetAnnotation(Class childClass) {
        Annotation annotation = childClass.getAnnotation(DocumentB.class);
        System.out.println(annotation);

        Annotation DocumentA = childClass.getAnnotation(com.tx.review.annotation.Inherited.DocumentA.class);
        System.out.println(DocumentA);

        Annotation MyDoc = childClass.getAnnotation(com.tx.review.annotation.doc.MyDoc.class);
        System.out.println(MyDoc);
    }
}


@DocumentA
class Base{

}

@DocumentB
class Child extends Base{

    public Child() {

    }
}